import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';

class DrawerScreen extends StatefulWidget {
  @override
  DrawerScreenState createState() => DrawerScreenState();
}

class DrawerScreenState extends State<DrawerScreen> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('带抽屉的页面'),
      ),
      body: MyBody(),
      drawer: MyDrawer(),
      bottomNavigationBar: BottomAppBar(
        color: Colors.white,
        shape: CircularNotchedRectangle(),
        child: Row(
          children: <Widget>[
            IconButton(icon: Icon(Icons.home), onPressed: null),
            //空出中间显示的位置
            SizedBox(),
            IconButton(icon: Icon(Icons.business), onPressed: null),
          ],
          //均分底部导航栏横向空间
          mainAxisAlignment: MainAxisAlignment.spaceAround,
        ),
      ),
      //把floatingAction按钮放到底部导航中间
      floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,

      floatingActionButton: FloatingActionButton(
          child: Icon(Icons.add),
          onPressed: () => Fluttertoast.showToast(msg: "点击了FloatAction按钮")),
    );
  }
}

class MyBody extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Center(
      child: Text("主题部分"),
    );
  }
}

class MyDrawer extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Drawer(
      //移除顶部padding
      child: MediaQuery.removePadding(
          context: context,
          removeTop: true,
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              //构建抽屉头
              _buildHeader(context),
              //构建抽屉菜单
              Expanded(child: _buildMenus()),
            ],
          )),
    );
  }

  Widget _buildHeader(BuildContext context) {
    return GestureDetector(
      child: Container(
          color: Theme.of(context).primaryColor,
          height: 200,
          padding: EdgeInsets.only(top: 40, bottom: 20),
          child: Row(
            children: <Widget>[
              Padding(
                padding: const EdgeInsets.symmetric(horizontal: 16.0),
                child: ClipOval(
                  child: Icon(
                    Icons.account_circle,
                    size: 100,
                  ),
                ),
              ),
              Text("用户昵称"),
            ],
          )),
      onTap: () {
        Fluttertoast.showToast(msg: "点击了头像");
//        if (value.userId.isNotEmpty) {
//          Navigator.of(context).pushNamed("login");
//        }
      },
    );
//    return Consumer<UserModel>(
//      builder: (BuildContext context, UserModel value, Widget child) {
//
//      },
//    );
  }

  Widget _buildMenus() {
    return ListView(
      children: <Widget>[
        ListTile(
            leading: const Icon(Icons.color_lens),
            title: Text("主题"),
            onTap: () => Fluttertoast.showToast(msg: "点击了主题")),
        ListTile(
            leading: const Icon(Icons.language),
            title: Text("语言"),
            onTap: () => Fluttertoast.showToast(msg: "点击了语音"))
      ],
    );
//    return Consumer<UserModel>(
//        builder: (BuildContext context, UserModel userModel, Widget child){
//
//        }
//    );
  }
}
